package com.app.teaware.bean;

import com.alibaba.fastjson.annotation.JSONField;
import com.app.teaware.basis.Constants;
import com.app.teaware.greendao.GreenDaoUtils;

import java.util.ArrayList;
import java.util.Calendar;

import my.FileUtils;
import my.LogUtil;
import my.TimeUtils;

public class BaseInfoUpdateCache extends BasisBean {

    private boolean needUpdateUnit = true;    //重量单位



    private boolean needUpdateUnitWhole = true;    //整件单位
    private boolean needUpdateBox = true;        //纸箱
    private boolean needUpdateTray = true;          //托盘
    private boolean needUpdateCustomer = true;          //客户
    private boolean needUpdateCraft = true;          //工艺
    private boolean needUpdateGoods = true;          //货品
    private boolean needUpdateLocation = true;          //楼层
    private boolean needUpdateSpecies = true;          //货品分类


    private int unitCount;
    private int unitWholeCount;
    private int boxCount;
    private int trayCount;
    private int customerCount;
    private int craftCount;
    private int goodsCount;
    private int locationCount;
    private int speciesCount;


    private int unitCountUpdated;
    private int unitWholeCountUpdated;
    private int boxCountUpdated;
    private int trayCountUpdated;
    private int customerCountUpdated;
    private int craftCountUpdated;
    private int goodsCountUpdated;
    private int locationCountUpdated;
    private int speciesCountUpdated;

    private boolean isForceUpdate = false;


    @JSONField(serialize = false)
    public boolean isNeedUpdate(){
        if(isForceUpdate )return true;
        LogUtil.i("-----time111---"+ TimeUtils.getCurrentTimeByFormat("HH:mm:ss"));
        LogUtil.i("ContactListBean.isCacheExist()---?"+ContactListBean.isCacheExist());

        if( needUpdateUnit ){
            needUpdateUnit = (unitCount > 0);
        }

        if( needUpdateUnitWhole ){
            needUpdateUnitWhole = (unitWholeCount > 0);
        }

        if( needUpdateBox ){
            needUpdateBox = (boxCount > 0);
        }

        if( needUpdateTray ){
            needUpdateTray = (trayCount > 0);
        }

        if( needUpdateCustomer ){
            needUpdateCustomer = (customerCount > 0);
        }

        if( needUpdateCraft ){
            needUpdateCraft = (craftCount > 0);
        }

        if( needUpdateGoods ){
            needUpdateGoods = (goodsCount > 0);
        }
        if( needUpdateLocation ){
            needUpdateLocation = (locationCount > 0);
        }
        if( needUpdateSpecies ){
            needUpdateSpecies = (speciesCount > 0);
        }


        LogUtil.i("-----time222---"+ TimeUtils.getCurrentTimeByFormat("HH:mm:ss"));
        if( needUpdateUnit||needUpdateUnitWhole
                ||needUpdateBox||needUpdateTray||needUpdateCustomer
                ||needUpdateCraft||needUpdateGoods||needUpdateLocation
                ||needUpdateSpecies)return true;

            return false;
    }

    @JSONField(serialize = false)
    public void setUpdateCountByType(String map_type,int  count){
        switch (map_type){
            case GreenDaoUtils.TYPE_UNIT:
                unitCount = count;
                break;
            case GreenDaoUtils.TYPE_WHOLE_UNIT:
                unitWholeCount = count;
                break;
            case GreenDaoUtils.TYPE_TRAY:
                trayCount = count;
                break;
            case GreenDaoUtils.TYPE_BOX:
                boxCount = count;
                break;
            case GreenDaoUtils.TYPE_CUSTOMER:
                customerCount = count;
                break;
            case GreenDaoUtils.TYPE_CRAFT:
                craftCount = count;
            case GreenDaoUtils.TYPE_GOODS:
                goodsCount = count;
                break;
            case GreenDaoUtils.TYPE_LOCATION:
                locationCount = count;
                break;
            case GreenDaoUtils.TYPE_SPECIES:
                speciesCount = count;
                break;
        }
    }

    @JSONField(serialize = false)
    public boolean isUpdateSuccess(){
        if( (unitCountUpdated == 0) && (unitWholeCountUpdated == 0)
                && (trayCountUpdated == 0)&& (boxCountUpdated == 0)
                && (customerCountUpdated == 0)  && (craftCountUpdated == 0) && (goodsCountUpdated == 0)
                && (goodsCountUpdated == 0)& (speciesCountUpdated == 0)){
            return false;
        }

        return true;
    }


    @JSONField(serialize = false)
    public void setUpdatedCountByMaptype(String type,int updatedCount){
        switch (type){
            case GreenDaoUtils.TYPE_UNIT:
                unitCountUpdated = updatedCount;
                break;
            case GreenDaoUtils.TYPE_WHOLE_UNIT:
                unitWholeCountUpdated = updatedCount;
                break;
            case GreenDaoUtils.TYPE_TRAY:
                trayCountUpdated = updatedCount;
                break;
            case GreenDaoUtils.TYPE_BOX:
                boxCountUpdated = updatedCount;
                break;
            case GreenDaoUtils.TYPE_CUSTOMER:
                customerCountUpdated = updatedCount;
                break;
            case GreenDaoUtils.TYPE_CRAFT:
                craftCountUpdated = updatedCount;
                break;
            case GreenDaoUtils.TYPE_GOODS:
                goodsCountUpdated = updatedCount;
                break;
            case GreenDaoUtils.TYPE_LOCATION:
                locationCountUpdated = updatedCount;
                break;
            case GreenDaoUtils.TYPE_SPECIES:
                speciesCountUpdated = updatedCount;
                break;

        }
    }


    @JSONField(serialize = false)
    public void setAllNeedUpdate(boolean isNeed){
        needUpdateUnit = isNeed;
        needUpdateUnitWhole = isNeed;
        needUpdateBox = isNeed;
        needUpdateTray = isNeed;
        needUpdateCustomer = isNeed;
        needUpdateCraft = isNeed;
        needUpdateGoods = isNeed;
        needUpdateLocation = isNeed;
        needUpdateSpecies= isNeed;
    }

    public int getUnitCountUpdated() {
        return unitCountUpdated;
    }

    public void setUnitCountUpdated(int unitCountUpdated) {
        this.unitCountUpdated = unitCountUpdated;
    }


    public int getTrayCountUpdated() {
        return trayCountUpdated;
    }

    public void setTrayCountUpdated(int trayCountUpdated) {
        this.trayCountUpdated = trayCountUpdated;
    }

    public boolean isNeedUpdateCustomer() {
        return needUpdateCustomer;
    }

    public void setNeedUpdateCustomer(boolean needUpdateCustomer) {
        this.needUpdateCustomer = needUpdateCustomer;
    }

    public int getCustomerCount() {
        return customerCount;
    }

    public void setCustomerCount(int customerCount) {
        this.customerCount = customerCount;
    }


    public int getTrayCount() {
        return trayCount;
    }

    public void setTrayCount(int trayCount) {
        this.trayCount = trayCount;
    }

    public int getUnitCount() {
        return unitCount;
    }

    public void setUnitCount(int unitCount) {
        this.unitCount = unitCount;
    }


    public boolean isNeedUpdateUnit() {
        return needUpdateUnit;
    }

    public void setNeedUpdateUnit(boolean needUpdateUnit) {
        this.needUpdateUnit = needUpdateUnit;
    }


    public boolean isNeedUpdateTray() {
        return needUpdateTray;
    }

    public void setNeedUpdateTray(boolean needUpdateTray) {
        this.needUpdateTray = needUpdateTray;
    }


    public boolean isForceUpdate() {
        return isForceUpdate;
    }

    public void setForceUpdate(boolean forceUpdate) {
        isForceUpdate = forceUpdate;
    }
    public int getCustomerCountUpdated() {
        return customerCountUpdated;
    }

    public void setCustomerCountUpdated(int customerCountUpdated) {
        this.customerCountUpdated = customerCountUpdated;
    }

    public boolean isNeedUpdateCraft() {
        return needUpdateCraft;
    }

    public void setNeedUpdateCraft(boolean needUpdateCraft) {
        this.needUpdateCraft = needUpdateCraft;
    }

    public int getCraftCount() {
        return craftCount;
    }

    public void setCraftCount(int craftCount) {
        this.craftCount = craftCount;
    }

    public int getCraftCountUpdated() {
        return craftCountUpdated;
    }

    public void setCraftCountUpdated(int craftCountUpdated) {
        this.craftCountUpdated = craftCountUpdated;
    }

    public boolean isNeedUpdateBox() {
        return needUpdateBox;
    }

    public void setNeedUpdateBox(boolean needUpdateBox) {
        this.needUpdateBox = needUpdateBox;
    }

    public int getBoxCount() {
        return boxCount;
    }

    public void setBoxCount(int boxCount) {
        this.boxCount = boxCount;
    }

    public int getBoxCountUpdated() {
        return boxCountUpdated;
    }

    public void setBoxCountUpdated(int boxCountUpdated) {
        this.boxCountUpdated = boxCountUpdated;
    }

    public boolean isNeedUpdateGoods() {
        return needUpdateGoods;
    }

    public void setNeedUpdateGoods(boolean needUpdateGoods) {
        this.needUpdateGoods = needUpdateGoods;
    }

    public int getGoodsCount() {
        return goodsCount;
    }

    public void setGoodsCount(int goodsCount) {
        this.goodsCount = goodsCount;
    }

    public int getGoodsCountUpdated() {
        return goodsCountUpdated;
    }

    public void setGoodsCountUpdated(int goodsCountUpdated) {
        this.goodsCountUpdated = goodsCountUpdated;
    }


    public boolean isNeedUpdateLocation() {
        return needUpdateLocation;
    }

    public void setNeedUpdateLocation(boolean needUpdateLocation) {
        this.needUpdateLocation = needUpdateLocation;
    }

    public int getLocationCount() {
        return locationCount;
    }

    public void setLocationCount(int locationCount) {
        this.locationCount = locationCount;
    }

    public int getLocationCountUpdated() {
        return locationCountUpdated;
    }

    public void setLocationCountUpdated(int locationCountUpdated) {
        this.locationCountUpdated = locationCountUpdated;
    }
    public boolean isNeedUpdateSpecies() {
        return needUpdateSpecies;
    }

    public void setNeedUpdateSpecies(boolean needUpdateSpecies) {
        this.needUpdateSpecies = needUpdateSpecies;
    }

    public int getSpeciesCount() {
        return speciesCount;
    }

    public void setSpeciesCount(int speciesCount) {
        this.speciesCount = speciesCount;
    }

    public int getSpeciesCountUpdated() {
        return speciesCountUpdated;
    }

    public void setSpeciesCountUpdated(int speciesCountUpdated) {
        this.speciesCountUpdated = speciesCountUpdated;
    }

    public boolean isNeedUpdateUnitWhole() {
        return needUpdateUnitWhole;
    }

    public void setNeedUpdateUnitWhole(boolean needUpdateUnitWhole) {
        this.needUpdateUnitWhole = needUpdateUnitWhole;
    }

    public int getUnitWholeCount() {
        return unitWholeCount;
    }

    public void setUnitWholeCount(int unitWholeCount) {
        this.unitWholeCount = unitWholeCount;
    }

    public int getUnitWholeCountUpdated() {
        return unitWholeCountUpdated;
    }

    public void setUnitWholeCountUpdated(int unitWholeCountUpdated) {
        this.unitWholeCountUpdated = unitWholeCountUpdated;
    }













    public static final String FILE_CACHE = Constants.DIR_FILECACHE
            + "tea_ware_baseinfo_update_cache_.data";

    @JSONField(serialize = false)
    public static BaseInfoUpdateCache getFromCache() {
        BaseInfoUpdateCache data = (BaseInfoUpdateCache) FileUtils.readObject(FILE_CACHE);
        if (data == null) {
            data = new BaseInfoUpdateCache();
        }
        return data;
    }

    @JSONField(serialize = false)
    public void save() {
        isForceUpdate =false;
        FileUtils.cacheObject(FILE_CACHE, this);
    }
    @JSONField(serialize = false)
    public static void delete() {
        FileUtils.cacheObject(FILE_CACHE, null);
    }

}
